<template>
  <div>
    <div class="page-title">
      <div class="left-color"></div>
      <div class="title">分支结构 <span>/查看分支机构档案详情</span></div>
    </div>

    <div class="organization-box">
      <div
        class="organization"
        v-for="(organiz, index) in organizations"
        :key="'organiz' + index"
      >
        <div
          class="organization-item"
          @click="toApplyApproval(organiz.userInfo.userId)"
        >
          <div class="left">
            <div class="organiz-title">{{organiz.departmentName}} - {{ organiz.name }}</div>
            <div class="organiz-detail">
              <i class="el-icon-star-off"></i> 共{{
                organiz.userInfo && organiz.userInfo.boxCount
              }}窍
            </div>
            <div class="organiz-detail">
              <i class="el-icon-user-solid"></i>
              {{ organiz.userInfo && organiz.userInfo.name }} ({{
                organiz.userInfo && organiz.userInfo.mobile
              }})
            </div>
          </div>

          <div class="right">
            <img v-if="icon" :src="icon" alt="窍楚">
            <img v-else src="@/assets/images/default.png" alt="窍楚" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserBoxCount } from "@/api/boss/index";
export default {
  name: "Home",
  components: {},
  data() {
    return {
      activeIndex: "1",
      activeIndex2: "1",
      // 如果是boss账号， 到登录用户信息中获得
      organizations: [],
      mainUserIds: "",
      icon: ''
    };
  },
  created() {
    const fullUserInfo = JSON.parse(localStorage.getItem("localUserInfo"));
    this.organizations = fullUserInfo.childDepartmentList;
    this.mainUserIds = fullUserInfo.id;

    this.organizations = this.organizations.map(e => {
      return {
        ...e,
        userInfo: {
          userId: e.userId,
          boxCount: e.boxCount,
          name: e.name,
          mobile: e.mobile,
          departmentName: e.departmentName
        }
      }
    })

    if (JSON.parse(localStorage.getItem("domainInfo")).icon ) {
      this.icon = JSON.parse(localStorage.getItem("domainInfo")).icon
    }
    // this.getBoxNum();
  },
  methods: {
    // // 获得不同部门的窍数
    // getBoxNum() {
    //   getUserBoxCount().then((res) => {
    //     this.organizations = this.organizations.map((e) => {
    //       return e = {
    //         ...e,
    //         userInfo:res.data.filter(s => s.departmentId == e.id)[0]
    //       }
    //       // if (res.data[e.mainUserId]) {
    //       //   e["userInfo"] = res.data[e.mainUserId];
    //         // this.$forceUpdate();
    //       // }
    //     });
    //   });
    // },
    // 传参 进入待调阅列表
    toApplyApproval(mainUserId) {
      this.$router.push({
        // path: "/retrieval/apply",
        name: "applyRead",
        params: { userId: mainUserId },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.page-title {
  padding: 10px 0 10px 0;
  font-size: 22px;
  line-height: 50px;
  display: flex;
  .left-color {
    height: 50px;
    width: 5px;
    background-color: #f88123;
    margin-right: 12px;
  }
  .title {
    span {
      font-size: 14px;
    }
  }
}
.organization-box {
  display: flex;
  flex-wrap: wrap;
  .organization {
    width: calc(25% - 20px);
    height: 140px;
    border: 1px solid #eee;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    margin-top: 20px;
    margin-right: 20px;
    cursor: pointer;

    .organization-item {
      height: 100%;
      padding: 0 5px 0 15px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .organiz-title {
        font-size: 23px;
        height: 35px;
      }
      .organiz-detail {
        line-height: 20px;
      }
    }
  }
}
</style>
